/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.common.nonlitigation.controller;

import com.icinfo.cloud.common.core.Validator.BaseGroup;
import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.common.nonlitigation.dto.CaseNonLitigationExecutePageRequest;
import com.icinfo.cloud.provider.punish.common.nonlitigation.dto.CaseNonLitigationExecuteRequestDto;
import com.icinfo.cloud.provider.punish.common.nonlitigation.dto.NonLitigationExecuteConditionRecordQueryDto;
import com.icinfo.cloud.provider.punish.common.nonlitigation.model.CaseNonLitigationExecuteRecord;
import com.icinfo.cloud.provider.punish.common.nonlitigation.service.ICaseNonLitigationExecuteRecordService;
import com.icinfo.cloud.provider.punish.common.nonlitigation.vo.CaseNonLitigationExecuteDetailVo;
import com.icinfo.cloud.provider.punish.common.nonlitigation.vo.CaseNonLitigationExecuteRecordDetailVo;
import com.icinfo.cloud.provider.punish.common.nonlitigation.vo.CaseNonLitigationExecuteRecordVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 描述: 非诉执行记录表 case_non_litigation_execute_record 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年04月07日
 */
@RestController
@RefreshScope
@RequestMapping("/punish/nonlitigation")
@Slf4j
public class CaseNonLitigationExecuteRecordController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(CaseNonLitigationExecuteRecordController.class);

    @Resource
    private ICaseNonLitigationExecuteRecordService caseNonLitigationExecuteRecordService;

    /**
     * 描述：行政非诉智审网上立案
     *
     * @return {@link Result<String> }
     * @author shishengyao
     * @date 2022/04/07
     */
    @PostMapping("/saveNonLitigationExecuteRegister")
    @ApiOperation(value = "【V1.0.0】描述：获取案件证据列表", httpMethod = "POST")
    public Result<String> saveNonLitigationExecuteRegister(HttpServletRequest request, @RequestBody @Validated CaseNonLitigationExecuteRequestDto requestDto) {
        requestDto.setIpAddress(request.getRemoteAddr());
        Map<String, Object> result = caseNonLitigationExecuteRecordService.nonLitigationExecuteRegister(requestDto);
        if (Constant.STRING_SUCCESS_EN.equals(result.get("code"))) {
            return Result.success("非诉执行立案成功");
        } else {
            return Result.error(result.get("errorMsg").toString());
        }

    }

    /**
     * 【V1.1.0】描述：非诉执行分页查询
     *
     * @param request
     * @return {@link Result < PageResponse< ConfigCaseApprovalCenterVo>>}
     * @author liyafeng
     * @date 2022/4/1
     */
    @PostMapping("/getNonLitigationExecuteRecordList")
    public Result<PageResponse<CaseNonLitigationExecuteRecordVo>> getNonLitigationExecuteRecordList(@RequestBody @Validated CaseNonLitigationExecutePageRequest request) {
        List<CaseNonLitigationExecuteRecordVo> caseNonLitigationExecuteVoList = caseNonLitigationExecuteRecordService.getCaseNonLitigationExecuteVoList(request);
        return Result.success("查询成功", new PageResponse<>(caseNonLitigationExecuteVoList));
    }

    /**
     * 【V1.1.0】描述：获取非诉执行立案执行情况
     *
     * @return {@link Result<CaseNonLitigationExecuteRecordDetailVo> }
     * @author shishengyao
     * @date 2022/05/12
     */
    @PostMapping("/getNonLitigationExecuteDetail")
    public Result<CaseNonLitigationExecuteDetailVo> getNonLitigationExecuteDetail(@RequestBody @Validated(BaseGroup.Query.class) NonLitigationExecuteConditionRecordQueryDto queryDto) {
        CaseNonLitigationExecuteDetailVo recordVo = caseNonLitigationExecuteRecordService.getNonLitigationExecuteDetail(queryDto);

        return Result.success("");
    }

    /**
     * 【V2.0.0】描述：获取非诉执行立案执行情况记录信息
     *
     * @return {@link Result<CaseNonLitigationExecuteRecordDetailVo> }
     * @author shishengyao
     * @date 2022/05/12
     */
    @PostMapping("/getNonLitigationExecuteConditionRecord")
    public Result<CaseNonLitigationExecuteRecordDetailVo> getNonLitigationExecuteConditionRecord(@RequestBody @Validated(BaseGroup.Query.class) NonLitigationExecuteConditionRecordQueryDto queryDto) {
        CaseNonLitigationExecuteRecordDetailVo recordVo = caseNonLitigationExecuteRecordService.getNonLitigationExecuteConditionRecord(queryDto);
        return Result.success("查询成功", recordVo);
    }

    /**
     * 【V2.0.0】描述：获取非诉执行立案执行情况记录信息
     *
     * @return {@link Result<CaseNonLitigationExecuteRecordDetailVo> }
     * @author shishengyao
     * @date 2022/05/12
     */
    @PostMapping("/saveNonLitigationExecuteAutoRecord")
    public Result<CaseNonLitigationExecuteRecordDetailVo> saveNonLitigationExecuteAutoRecord(@RequestBody @Validated(BaseGroup.Query.class) NonLitigationExecuteConditionRecordQueryDto queryDto) {
        CaseNonLitigationExecuteRecord recordVo = caseNonLitigationExecuteRecordService.getCaseNonLitigationExecuteRecordByCaseId(queryDto.getCaseId());
        caseNonLitigationExecuteRecordService.saveNonLitigationExecuteAutoRecord(recordVo);
        return Result.success("查询成功");
    }

    /**
     * 【1.9.2】保存非诉讼执行自动记录
     *
     * @param queryDto 查询dto
     * @return {@link Result<CaseNonLitigationExecuteRecordDetailVo> }
     * @author shishengyao
     * @date 2022/12/05
     */
    @PostMapping("/saveExecuteResult")
    public Result<CaseNonLitigationExecuteRecordDetailVo> saveExecuteResult(@RequestBody @Validated(BaseGroup.Query.class) NonLitigationExecuteConditionRecordQueryDto queryDto) {
        CaseNonLitigationExecuteRecord recordVo = caseNonLitigationExecuteRecordService.getCaseNonLitigationExecuteRecordByCaseId(queryDto.getCaseId());
        caseNonLitigationExecuteRecordService.saveNonLitigationExecuteAutoRecord(recordVo);
        return Result.success("查询成功");
    }


}
